import * as echarts from 'echarts'
export type eOption = echarts.EChartsOption
export default class BaseChart {
    chartDom: HTMLElement
    myChart: echarts.ECharts
    constructor(id: string) {
        this.chartDom = document.getElementById(id) as HTMLElement
        this.myChart = echarts.init(this.chartDom)
    }
    init(option: eOption) {
        option && this.myChart.setOption(option)
        window.addEventListener('resize', this.resize, false)
    }
    destory() {
        //先判断实例是否被销毁
        if (!this.myChart.isDisposed()) {
            window.removeEventListener('resize', this.resize, false)
            this.myChart.dispose()
        }
    }
    resize = () => {
        this.myChart.resize()
    }
}
